package gnssio

type CommListener struct {
	OnRecv         func(sender I_Comm, buf []byte)
	OnConnected    func(sender I_Comm)
	OnDisconnected func(sender I_Comm)
}

func NewCommListener(onRecv func(sender I_Comm, buf []byte),
	onConnected func(sender I_Comm),
	onDisconnected func(sender I_Comm)) *CommListener {
	rval := &CommListener{OnRecv: onRecv, OnConnected: onConnected, OnDisconnected: onDisconnected}
	return rval
}

func (this *CommListener) OnReceive(sender I_Comm, buf []byte, l int) {
	if this.OnRecv != nil {
		this.OnRecv(sender, buf[:l])
	}
}

func (this *CommListener) OnConnect(sender I_Comm) {
	if this.OnConnected != nil {
		this.OnConnected(sender)
	}
}

func (this *CommListener) OnDisconnect(sender I_Comm) {
	if this.OnDisconnected != nil {
		this.OnDisconnected(sender)
	}
}
